package com.realworld.common;

import lombok.Data;


@Data
public class R<T> {
    private Integer code;
    private String msg;
    private T data;

    public R(Integer code,String msg,T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public R(Integer code,String msg){
        this.code = code;
        this.msg = msg;
    }
    public R(T data,Integer code){
        this.code = code;
        this.data = data;
    }
    public R(T data){
        this.data = data;
        this.msg = "success";
        this.code = 1024;
    }

    public static <T> R<T> ok(Integer code,String msg){
        return new R<>(code,msg);
    }
    public static <T> R<T> ok(Integer code,String msg,T data){
        return new R(code,msg,data);
    }
    public static <T> R<T> ok(T data,Integer code){
        return new R(data,code);
    }
    public static <T> R<T> ok(T data){
        return new R<>(data);
    }

    public static <T> R<T> error(Integer code,String msg){
        throw new ExceptionData(code,msg);
    }
}
